package com.lms.micrometer;

import io.micrometer.core.instrument.Measurement;
import io.micrometer.core.instrument.Meter;
import io.micrometer.core.instrument.Metrics;
import io.micrometer.core.instrument.Tags;
import io.micrometer.core.instrument.simple.SimpleMeterRegistry;

import javax.management.ObjectName;
import java.lang.management.BufferPoolMXBean;
import java.lang.management.ManagementFactory;
import java.lang.management.MemoryMXBean;
import java.lang.management.MemoryUsage;
import java.util.List;

/**
 * @Author: 李孟帅
 * @CreateTime: 2020-06-11 18:07
 * @Description:
 */
public class MeterDemo {
    public static void main(String[] args) {
//        String s="";
//        for (int i = 0; i < 10000; i++) {
//            s+=i;
//        }
        SimpleMeterRegistry simpleMeterRegistry = new SimpleMeterRegistry();
        simpleMeterRegistry.counter("jvm.mem.max", Tags.of("qps", "value"));
        Metrics.addRegistry(simpleMeterRegistry);
        MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
        System.out.println(memoryMXBean.getHeapMemoryUsage());
        System.out.println(memoryMXBean.getNonHeapMemoryUsage());
        System.out.println(memoryMXBean.getObjectPendingFinalizationCount());
        System.out.println(memoryMXBean.getObjectName());
        System.out.println(memoryMXBean.isVerbose());
        memoryMXBean.gc();
        System.out.println("-------");
        System.out.println(ManagementFactory.getMemoryMXBean().getHeapMemoryUsage());


    }
}
